
<{capture name="header"}>
<{css app="ome" src="ome.css"}>
<{/capture}>

<!--
<{*<{if $up_order or $next_order}>
<{capture name='headbar'}>
<table cellspacing="0" cellpadding="0" style="border-width:0 0 1px;" class="table-action">
  <tbody><tr valign="middle">
      <td>
        <{if $up_order}>
        <{button label='上一条' class="btn btn-primary" id="btn_prev" onclick="window.location='index.php?app=ome&ctl=admin_order&act=do_confirm&p[0]={$up_order.order_id}&filter={$filter}&find_id={$finder_id}';" }>
        <{else}>

        <{/if}>
        <{if $next_order}>
        <{button label='下一条' class="btn btn-primary" id="btn_next" onclick="window.location='index.php?app=ome&ctl=admin_order&act=do_confirm&p[0]={$next_order.order_id}&filter={$filter}&find_id={$finder_id}';" }>
        <{else}>

        <{/if}>
      </td>
    </tr>
  </tbody>
</table>
<{/capture}>
<{/if}>*}>-->
<form class="tableform" style="background:#fff; border:0 none;" method="post" action="index.php?app=ome&ctl=admin_order&act=finish_confirm" id="order_split">
  <input type="hidden" name="order_id" value="<{$order_id}>"/>
  <input type="hidden" name="do_action" id="do_action" value=""/>
  <input type="text" style="display:none" />

  <div id="nosplitarea">
    <div class="finder-detail" style="margin:0 5px">
      <h3 style="border-bottom:none;" class="fl">发货单信息</h3>
      <table  cellspacing="0" cellpadding="0" border="0" style="margin:5px 0;width:auto; float:right;">
        <tbody>
          <tr>
            <td  style="text-align: right; padding-bottom:5px;">
              库存说明：
              <span style="padding: 5px; border:1px solid #cddfcd;" class="ColColorGreen">库存充足</span>
              <span style="padding: 5px; border:1px solid #decacc;" class="ColColorRed">库存紧张</span>
              <span style="padding: 5px; border:1px solid #cecece;" class="ColColorGray">缺货</span>
            </td>
          </tr>
        </tbody>
      </table>

      <{include file="admin/order/confirm/product_confirm.html"}>

      <table class="gridlist">
        <thead>
          <tr>
            <th style="text-align:left;">配送信息 <a href="javascript:void(0);" id="other_delivery">使用其它配送信息</a></th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td id="delivery_info">
              <{include file="admin/order/confirm/delivery_info.html"}>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <div id="issplit" class="issplit" style="display:none;">
      <table cellspacing="0" cellpadding="0" border="0">
        <tr>
          <td class="fontcolorRed fontbold font14px">已拆分-</td>
          <td width="230" style="text-align: center; font-weight: normal;">
            快递公司选择：<div class="corp_list"></div>
          </td>
        </tr>
      </table>
      <table cellspacing="0" class="gridlist" cellpadding="2" border="0">
        <thead>
          <tr>
            <th>货号</th>
            <th>商品名称</th>
            <th>数量</th>
            <th>仓库</th>
            <th style="width:100px;">操作</th>
          </tr>
        </thead>
        <tbody>

        </tbody>
      </table>
    </div>
  </div>

  <div id="issplitarea"></div>

  <div class="finder-detail" style="margin-top:10px;">
    <div class="clearfix"><h3 class="fl">订单信息</h3><div class="fr" style="margin:6px 10px 0 0;"><a href="javascript:void(0);" id="show_order">更多>></a></div></div>
    <div class="division" style="background:#fff; height:58px; overflow:hidden;" id="order_area">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody><tr>
            <th>订单号：</th>
            <td><span id="order_bn"><{$order.order_bn}></span> <a href="javascript:void(0);" id="btn_copy" class="lnk">[复制]</a></td>
            <th><b>订单总金额：</b></th>
            <td><b><{$order.total_amount|cur}></b></td>
            <th>订单折扣或涨价：</th>
            <td><{$order.discount|cur}></td>
          </tr>
          <tr>
            <th>下单日期：</th>
            <td><{$order.createtime}> <span style="color:#84A2AD;">(至今<{$order.difftime}>)</span></td>
            <th>配送费用：</th>
            <td><{$order.shipping.cost_shipping|cur}></td>
            <th>支付方式：</th>
            <td><{$order.payinfo.pay_name}></td>
          </tr>
          <tr>
            <th>商品总金额：</th>
            <td><{$order.cost_item|cur}></td>
            <th>配送方式：</th>
            <td><{$order.shipping.shipping_name}></td>
            <th>支付手续费：</th>
            <td><{$order.payinfo.cost_payment|cur}> </td>
          </tr>
          <tr>
            <th>订单优惠金额：</th>
            <td><{$order.pmt_order|cur}></td>
            <th>保价：</th>
            <td><{$order.shipping.cost_protect|cur}> <span style="color:#84A2AD;">是否要保价：<{if $order.shipping.is_protect == 'true'}>是<{else}>否<{/if}> </span></td>
            <th>税金：</th>
            <td><{$order.cost_tax|cur}> </td>
          </tr>
          <tr>
            <th>商品优惠金额：</th>
            <td><{$order.pmt_goods|cur}></td>
            <th>商品重量：</th>
            <td><{$order.weight}></td>
            <th>发票抬头：</th>
            <td><{$order.tax_title}></td>
          </tr>
          <tr>
            <th>已支付金额：</th>
            <td><{$order.payed|cur}></td>
            <th>支付币种：</th>
            <td><{$order.currency}></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
      </tbody></table>
      <div align="right"><a href="javascript:void(0);" id="fold_order"><{img src='bundle/upload.gif' app='desktop'}></a></div>
    </div>
  </div>

  <div class="finder-detail" style="margin-top:10px;">
    <div class="clearfix"><h3 class="fl">购买人信息</h3><div class="fr" style="margin:6px 10px 0 0;"><a href="javascript:void(0);" id="show_buyer">更多>></a></div></div>
    <div class="division" style="background:#fff; height:28px; overflow:hidden;" id="buyer_area">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody>
          <tr>
            <th>会员用户名：</th>
            <td><{$member.account.uname}></td>
            <th>姓名：</th>
            <td><{$member.contact.name}></td>
            <th>联系电话：</th>
            <td><{if $member.contact.phone.telephone && $member.contact.phone.mobile}><{$member.contact.phone.telephone}> / <{$member.contact.phone.mobile}><{elseif $member.contact.phone.telephone}><{$member.contact.phone.telephone}><{else}><{$member.contact.phone.mobile}><{/if}></td>
          </tr>
          <tr>
            <th>Email地址：</th>
            <td><{$member.contact.email}></td>
            <th>地区：</th>
            <td><{$member.contact.area|region}></td>
            <th>地址：</th>
            <td><{$member.contact.addr}></td>
          </tr>
          <tr>
            <th>邮政编码：</th>
            <td><{$member.contact.zipcode}></td>
            <th colspan="4">&nbsp;</th>
          </tr>
        </tbody>
      </table>
      <div align="right"><a href="javascript:void(0);" id="fold_buyer"><{img src='bundle/upload.gif' app='desktop'}></a></div>
    </div>
  </div>

  <{if $order.consigner.name || $order.consigner.mobile || $order.consigner.tel}>
  <div class="finder-detail" style="margin-top:10px;">
    <div class="clearfix"><h3 class="fl">发货人信息</h3><div class="fr" style="margin:6px 10px 0 0;"><a href="javascript:void(0);" id="show_seller">更多>></a></div></div>
    <div class="division" style="background:#fff; height:28px; overflow:hidden;" id="seller_area">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody>
          <tr>
            <th>联系人：</th>
            <td><{$order.consigner.name}></td>
            <th>固定电话：</th>
            <td><{$order.consigner.tel}></td>
            <th>手机号码：</th>
            <td><{$order.consigner.mobile}></td>
          </tr>
          <tr>
            <th>Email地址：</th>
            <td><{$order.consigner.email}></td>
            <th>地区：</th>
            <td><{$order.consigner.area|region}></td>
            <th>地址：</th>
            <td><{$order.consigner.addr}></td>
          </tr>
          <tr>
            <th>邮政编码：</th>
            <td><{$order.consigner.zip}></td>
            <th colspan="4">&nbsp;</th>
          </tr>
        </tbody>
      </table>
      <div align="right"><a href="javascript:void(0);" id="fold_seller"><{img src='bundle/upload.gif' app='desktop'}></a></div>
    </div>
  </div>
  <{/if}>

  <{if $sellagent}>
  <div class="finder-detail" style="margin-top:10px;">
    <div class="clearfix"><h3 class="fl">代销人信息</h3><div class="fr" style="margin:6px 10px 0 0;"><a href="javascript:void(0);" id="show_sellagent">更多>></a></div></div>
    <div class="division" style="background:#fff; height:28px; overflow:hidden;" id="sellagent_area">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody>
          <tr>
            <th>用户名：</th>
            <td><{$sellagent.member_info.uname}></td>
            <th>姓名：</th>
            <td><{$sellagent.member_info.name}></td>
            <th>性别：</th>
            <td><{if $sellagent.member_info.sex == 'male'}>男<{else}>女<{/if}></td>
            <th>出生日期：</th>
            <td><{$sellagent.member_info.birthday}></td>
            <th>E-mail：</th>
            <td><{$sellagent.member_info.email}></td>
          </tr>
          <tr>
            <th>地区：</th>
            <td><{$sellagent.member_info.area|region}></td>
            <th>详情地址：</th>
            <td><{$sellagent.member_info.addr}></td>
            <th>邮编：</th>
            <td><{$sellagent.member_info.zip}></td>
            <th>手机：</th>
            <td><{$sellagent.member_info.mobile}></td>
            <th>固定电话：</th>
            <td><{$sellagent.member_info.tel}></td>
          </tr>
          <tr>
            <th>网站名称：</th>
            <td><{$sellagent.website.name}></td>
            <th>网站域名：</th>
            <td><{$sellagent.website.domain}></td>
            <th>网站LOGO：</th>
            <td><{if $sellagent.website.logo}><a href="<{$sellagent.website.logo}>" target="_blank">查看</a><{/if}></td>
            <th colspan="4">&nbsp;</th>
          </tr>
        </tbody>
      </table>
      <div align="right"><a href="javascript:void(0);" id="fold_sellagent"><{img src='bundle/upload.gif' app='desktop'}></a></div>
    </div>
  </div>
  <{/if}>

</form>

<{capture name='footbar'}>
<table cellspacing="0" cellpadding="0" class="table-action">
  <tbody>
    <tr valign="middle">
      <td>
        <!--<{*<{if $order.process_status != "cancel"}>
        <{if $order.ship_status == 0 && $order.pause == 'false'}>
        <{button label="暂停" type="button" class="btn-primary" id="btn_pause"}>
        <{/if}>
        <{if $order.ship_status == 0 && $order.pause == 'true'}>
        <{button label="恢复" type="button" class="btn-primary" id="btn_return"}>
        <{button label="编辑" type="button" class="btn-primary" id="btn_edit" onclick="javascript:window.location='index.php?app=ome&ctl=admin_order&act=view_edit&p[0]={$order.order_id}&finder_id={$env.get.find_id}&filter={$filter}'"}>
        <{/if}>
        <{/if}>*}>-->

        <{if $order.process_status == "cancel" || $order.abnormal == "true" || $order.status != "active" || $order.confirm == 'Y'}>

        <{else}>
        <{button label="确认" type="button" class="btn-primary" id="btn_confirm"}>
        <{/if}>

        <{if $order.process_status == "unconfirmed" || $order.process_status == "cancel" || $order.process_status == "splited" || $order.abnormal == "true" || $order.status != "active" }>

        <{else}>
            <{if $order.shipping.is_cod == 'true' || $order.pay_status == '1'}>
                <{button label="生成发货单" type="button" class="btn-primary" id="btn_consign"}>
            <{/if}>
        <{/if}>

        <{if $order.process_status == "cancel" || $order.abnormal == "true" || $order.status != "active" || $order.confirm == 'Y'}>

        <{else}>
            <{if $order.shipping.is_cod == 'true' || $order.pay_status == '1'}>
                <{button label="确认并生成发货单" type="button" class="btn-primary" id="btn_con"}>
            <{/if}>
        <{/if}>
      </td>
    </tr>
</tbody></table>
<{/capture}>

<{script src="zeroclipboard.js" app="ome"}>
<script>
(function() {
    var clip = null;
    function initClip(el, txt) {
        ZeroClipboard.setMoviePath('<{$url}>/statics/js/zeroclipboard.swf');
        ZeroClipboard.setMoviePath('<{$url}>/statics/js/zeroclipboard10.swf');
        clip = new ZeroClipboard.Client();
        clip.setText('');
        clip.setHandCursor(true);
        clip.setCSSEffects(true);
        clip.addEventListener('mouseDown', function(client) {
            clip.setText(txt);
        });
        clip.addEventListener('complete', function() {
            return MessageBox.show('信息已经复制到剪切板');
        });
        clip.glue(el);
    }
    initClip('btn_copy', $('order_bn').get('text'));
    window.addEvent('resize', function() {
        clip.reposition();
    });

    var getCorps = this.getCorps = function(branch_id) {
        if (!branch_id) {
            $('logi_id').set('html', '<option>请先选择仓库</option>');
            return;
        }
        new Request({
            url: 'index.php?app=ome&ctl=admin_order&act=getCorps',
            method: 'post',
            data: 'branch_id=' + branch_id,
            onComplete: function(json) {
                if (!json) return;
                json = JSON.decode(json);
                var s = '';
                json.each(function(j, i) {
                    s += '<option value=' + j.corp_id + '>' + j.name + '</option>';
                });
                $('logi_id').set('html', s);
                $('logi_id').options[0].selected = true;
            }
        }).send();
    };

    if ($E('.content-main') && ! <{$is_splited}>) {
        new Element('div.error', {
            html: '订单中的部分货品已生成发货单，进入配货流程。订单中还有商品等待确认，请在此页面确认发货信息，点击“生成发货单”继续操作。',
            style: 'margin-top:10px;font-size:14px;font-weight:bold; line-height:28px; text-align:center;'
        }).inject($E('.content-main'), 'top');
    }
    var branch_id = $('dataNode').getParent().getElement('th.selected') ? $('dataNode').getParent().getElement('th.selected').get('data-storeid') : '',
    logi_id = $('logi_id'),
    issplitarea = $('issplitarea'),
    select_branch = $$('.select_branch'),
    order_split = $('order_split'),
    order_id = $E('[name=order_id]', $('order_split')).value,
    finder = opener.finderGroup['<{$finder_id}>'];

    $('show_order').addEvent('click', function() {
        $('order_area').setStyle('height', 'auto');
        this.set('html', '');
    });
    $('fold_order').addEvent('click', function() {
        $('order_area').setStyle('height', 58);
        $('show_order').set('html', '更多>>');
    });
    $('show_buyer').addEvent('click', function() {
        $('buyer_area').setStyle('height', 'auto');
        this.set('html', '');
    });
    $('fold_buyer').addEvent('click', function() {
        $('buyer_area').setStyle('height', 28);
        $('show_buyer').set('html', '更多>>');
    });
    $$('.show_consign').addEvent('click', function() {
        this.getParent('.division').getElement('.consign_area').setStyle('display', 'block');
        this.set('html', '');
    });
    $$('.fold_consign').addEvent('click', function() {
        this.getParent('.consign_area').setStyle('display', 'none');
        this.getParent('.division').getElement('.show_consign').set('html', '更多>>');
    });

    <{if $order.consigner.name || $order.consigner.mobile || $order.consigner.tel}>
        $('show_seller').addEvent('click', function() {
        $('seller_area').setStyle('height', 'auto');
        this.set('html', '');
    });
    $('fold_seller').addEvent('click', function() {
        $('seller_area').setStyle('height', 28);
        $('show_seller').set('html', '更多>>');
    });
    <{/if}>
    <{if $sellagent}>
    $('show_sellagent').addEvent('click',function(){
      $('sellagent_area').setStyle('height','auto');
      this.set('html','');
    });
    $('fold_sellagent').addEvent('click',function(){
      $('sellagent_area').setStyle('height',28);
      $('show_sellagent').set('html','更多>>');
    });
    <{/if}>

    //close
    if (select_branch.length == 0) {
        new Element('div.error', {
            html: '请为商品先关联仓库',
            style: 'margin-top:10px;font-size:14px;font-weight:bold; line-height:28px; text-align:center;'
        }).inject($E('.content-main'), 'top');
        $$('input, select, button').set('disabled', true);
        //$('btn_pause').set('disabled',false);
        //$('btn_edit') && $('btn_edit').hide();
        return;
    }

    getCorps(branch_id);
    var index = this.index = $E('.gridlist thead th.selected') ? $$('.gridlist thead th').indexOf($E('.gridlist thead th.selected')) : $$('.gridlist thead th').indexOf($E('.gridlist thead .select_branch').getParent('th'));
    getSendcount(index);

    function getSendcount(index) {
        if (!branch_id) return;
        var sendcount = $$('[name=obj_type_count]');
        sendcount.each(function(item) {
            new Function(item.value)();
        });
    }

    select_branch.each(function(item, i) {
        var p = item.getParent('th');
        var idx = item.getParent('tr').getElements('th').indexOf(item.getParent('th'));
        var flag = false;
        for (var j = 0, k = $$('#dataNode tr').length, tr; j < k; j++) {
            tr = $$('#dataNode tr')[j];
            if (tr.hasClass('disabled') || tr.hasClass('bindtitle')) continue;
            if (tr.getElements('td')[idx].get('text').trim() !== '0' || tr.getElements('td')[idx].get('text').trim() !== '-') {
                flag = true;
                break;
            }
        }
        if (!flag) return;

        item.addEvents({
            'click': function(e) {
                window.index = idx;
                this.getParent('tr').getElements('th.selected').removeClass('selected');
                p.addClass('selected');
                $E('.row-tips') && $E('.row-tips').destroy();
                branch_id = p.get('data-storeid');
                getCorps(branch_id);
                //order_split.getElement('input[name=branch_id]').set('value', branch_id);
                getSendcount(index);
            },
            'mouseenter': function(e) {
                if (p.hasClass('selected')) return;
                var tips = new Element('div.row-tips', {
                    html: '<div class="tips">选择它来发货</div>'
                }).inject(document.body).fade(1);
                tips.setStyles({
                    'width': p.getSize().x + 1,
                    'top': p.getPosition().y - 24,
                    'left': p.getPosition().x
                });
                //this.clone(true).inject(tips.getElement('.wrapper-div'));
                p.getPrevious().setStyle('border-right-color', '#84a2ad');
                p.setStyle('border-color', '#84a2ad');
            },
            'mouseleave': function() {
                $E('.row-tips') && $E('.row-tips').destroy();
                p.getPrevious().setStyle('border-right-color', '#C8D6DC');
                p.setStyle('border-color', '#C8D6DC');
            }
        });
    });

    $('other_delivery').addEvent('click', function(e) {
        new Request.HTML({
            url: 'index.php?app=ome&ctl=admin_order&act=do_confirm_delivery_info_edit&p[0]=' + order_id,
            method: 'get',
            update: $('delivery_info'),
            onComplete: function() {
                this.set('html', '');
            }.bind(this)
        }).send();
    });

    var input_number = new Element('input[type=number]').get('type') !== 'text';
    $$('#dataNode td.sendcounts input[type]:not(:readonly)').addEvents({
        'change': function() {
            if (!branch_id) return MessageBox.error('请先选择仓库!');
            if (isNaN(this.value) || this.value == '') {
                new Element('span.error', {html: '请输入数字'}).injectAfter(this);
                this.value = '0';
                return this.focus();
            }
        },
        'focus':function() {
            if(this.getNext('.error')) {
              this.getNext('.error').destroy();
            }
        }
    });

    $('btn_confirm') && $('btn_confirm').addEvent('click', function() {
        doAction(1);
    });
    $('btn_consign') && $('btn_consign').addEvent('click', function() {
        doAction(2);
    });
    $('btn_con') && $('btn_con').addEvent('click', function() {
        doAction(3);
    });
    //$('btn_pause')&&$('btn_pause').addEvent('click', function(){doAction(4);});
    //$('btn_return')&&$('btn_return').addEvent('click', function(){doAction(5);});
    function doAction(act) {
        if ((act == 2 || act == 3)) {
            if (!doprocess()) return;
        }
        if (act == 3) {
            act = "1-2";
        }
        $('do_action').value = act;
        order_split.fireEvent('submit', {
            stop: function() {}
        });
    }

    order_split.store('target', {
        onRequest: function() {
            if ($('btn_consign')) {
                $('btn_consign').set('disabled', 'true');
                $('btn_consign').getElements('span')[1].set('text', '拆分中');
            } else if ($('btn_con')) {
                $('btn_con').set('disabled', 'true');
                $('btn_con').getElements('span')[1].set('text', '确认并拆分中');
            }
        },
        onComplete: function(jsontext) {
            var json = Json.evaluate(jsontext);
            if (typeof(json.error) == 'undefined') {
                if (json.success == '成功：订单暂停成功' || json.success == '成功：订单恢复成功' || json.success == '成功：订单确认成功' || json.success == '成功：订单拆分成功') {
                    window.location = window.location.href;
                    try {
                        finder.refresh.delay(100, finder);
                    } catch(e) {}
                }
                else {
                    try {
                        finder.refresh.delay(100, finder);
                    } catch(e) {}
                    if (json.success == '成功：订单拆分完成' && $('btn_next')) $('btn_next').onclick();
                    else setTimeout('window.close()', 120);
                }
            }
        }
    });

    function doprocess() {
        if (!branch_id) return MessageBox.error('请先选择仓库！');
        if ($('btn_delivery_submit')) {
            return MessageBox.error('您的配送信息正处于编辑状态！');
        }

        var products = [];
        var process = $$('[name=obj_type_process]');
        process.each(function(item){
            products.combine(new Function('return '+ item.value)());
        });
        //log(products);return;
        if(!products.length) return MessageBox.error('没有可以生成发货单的商品！');
        new Element('input[type=hidden][name=order_items]', {
            value: encodeURI(JSON.encode({
                branch_id: branch_id,
                logi_id: $('logi_id').value,
                products: products
            }))
        }).inject(issplitarea, 'top');
        return true;
    }

    function toHiddenString(el, v) {
        if (arguments.length == 1) return '<input type="hidden" name="' + el.name + '" value="' + el.value + '">';
        return '<input type="hidden" name="' + el + '" value="' + v + '">';
    }

    function message(msg, el, opt) {
        msg = msg || '';
        el = el || document.body;
        var type = 'error',
        delay = 4000,
        id = '0',
        where = 'after';
        if (typeof opt == 'object') {
            type = opt.type || type;
            delay = $chk(opt.delay) ? opt.delay: delay;
            id = opt.id || id;
            where = opt.where || where;
        }
        else if (typeof opt == 'string') type = opt;
        else if (typeof opt == 'number') delay = opt;
        else if (typeOf(opt) == 'array') {
            type = opt[0] || type;
            delay = $chk(opt[1]) ? opt[1] : delay;
            id = opt[2] || id;
            where = opt[3] || where;
        }
        id = 'message_Box_' + id;
        var bool = type == 'show' ? null: type == 'success' ? true: false;
        var box = $(id) || new Element('span.' + type + '#' + id);
        box.show().setHTML(msg).inject(el, where);
        if (delay) box.hide.delay(delay, box);
        if (!bool) try {
            el.select();
        } catch(e) {}
        return bool;
    }
})();
</script>
